package awt.robot;

import static java.lang.Boolean.parseBoolean;
import static java.lang.System.getProperty;

import java.awt.AWTException;
import java.awt.Robot;

/**
 * In contrary of {@link java.awt.Robot} this one will wait until system is totally idle and background processes are finished thus all data are ready to be
 * tested and it is safe to continue GUI manipulation. By default any other delays then synchronisation are disabled to decrease testing time.
 * 
 * @author Mykhaylo Adamovych
 */
public class RobotImpl extends Robot {
    public static final String SP_ENABLE_ROBOT_DELAYS = "com.swissbank.bp.awt.robot.enableDelays";
    private final boolean enableDelays = parseBoolean(getProperty(SP_ENABLE_ROBOT_DELAYS, "false"));

    public RobotImpl() throws AWTException {
        super();
        setAutoWaitForIdle(true);
    }

    @Override
    public synchronized void delay(int ms) {
        if (enableDelays)
            super.delay(ms);
    }

    @Override
    public synchronized void waitForIdle() {
        Sync.waitForIdle();
    }
}
